#计数排序
def count_sort(arr):
    res = [None for i in range(len(arr))]
    max_arr = max(arr)
    c = [0 for i in range(max_arr + 1)]
    for a in arr:
        c[a] += 1
    for i in range(1, max_arr+1):
        c[i] += c[i-1]
    for i in range(len(arr)-1, -1, -1):
        res[c[arr[i]] - 1] = arr[i]
        c[arr[i]] -= 1
    return res
print(count_sort([5,5,5,2,3,8,1]))
